﻿@using LanDBom.Resources
@{
    ViewBag.Title = "Quotation_to_be_generated";
}


@section styles{
    <style>
        .HUNKM {
            width: 100%;
        }

            .HUNKM thead th, .HUNKM tbody td {
                width: 20%;
            }
    </style>
}
<from>
    <fieldset class="boun">
        <legend></legend>
        <div class="row bian">
            <label class="col-sm-3 breadcrumb-item">步骤七：待生产报价单</label>
            <ul id="lisul" class="row col-sm-5">
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu">7</li>&rArr;
                <li class="lisu"></li>
            </ul>
        </div>
    </fieldset>
</from>
<from class="from-horizontal">
    <div>
        <fieldset class="boun nav" style="padding-bottom:6px;">
            <legend class="len">@Resource.String155</legend>
            <div class="col-lg-3">@Resource.String163:<input type="text" style="width:150px;" id="txtbian" /></div>
            <div class="col-lg-3">@Resource.String164:<input type="text" style="width: 150px;" id="txtKH" /></div>
            <div class="col-lg-3">
                项目负责人:
                <select style="width:143px;height:23px;padding:1px;" id="XMfzr">
                </select>
            </div>
            <div calss="col-lg-3"><button id="findApp" class="btn-sm btn-secondary">@Resource.String155</button>&nbsp;&nbsp;<button id="reste" class="btn-sm btn-secondary">  @Html.ActionLink("回到首页", "Zuye", new { Controller = "Home", Action = "Zuye" }, new { @style = "color:#fff" })</button></div>
        </fieldset>
    </div>
    <div class="tab">
        <fieldset class="boun nav">
            <legend class="len">@Resource.String197</legend>
            <table class="table table-sm gun HUNKM" border="0">
                <thead class="thead-light">
                    <tr style="text-align:center">
                        <th scope="col">@Resource.String189</th>
                        <th scope="col">@Resource.String190</th>
                        <th scope="col">@Resource.String191</th>
                        <th scope="col">@Resource.String192</th>
                        <th scope="col">@Resource.String193</th>
                        <th scope="col">项目负责人</th>
                        <th scope="col">@Resource.String194</th>
                        <th scope="col">传递至ERP</th>
                    </tr>
                </thead>
                <tbody id="AppTable" style="height:500px;">
                </tbody>
            </table>
        </fieldset>
    </div>
</from>
@*选择对应标签*@
<div id="WT_dh_mb" style="display: none; position: absolute; border: 1px black solid; left: 20%; top: 30%; background-color: white; background-color: #f1f1f1">
    <div style="text-align: right; background-color: #84acde;" class="Tuodong">点击这里拖动窗体<span class="quxiao" style=" margin: 20px;"><i class="bi bi-x-square"></i></span></div>
    <div id="WJ_tjr" style="display:none"></div>
    <div style="margin: 20px 10px; padding: 10px; background-color: #fff;">
        <table class="table">
            <thead>
                <tr>
                    <td>文件名</td>
                    <td>对应公司</td>
                    <td>类型</td>
                    <td>备注</td>
                    <td>预览</td>
                </tr>
            </thead>
            <tbody id="Tbodys">
            </tbody>
        </table>
    </div>
</div>

@section scripts
{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        $(function () {
            $("#li8").css({ "color": "black", "background-color": "white" })
            Application_form_information()
            FUzher()
            //打印申请表信息
            function Application_form_information() {
                var txtbian = $("#txtbian").val();
                var txtKH = $("#txtKH").val();
                var txtqishi = $("#App_xiang").val();
                var Fzr = $("#XMfzr").val();
                $.ajax({
                    url: '/Home/Quotation_to_be_generated',
                    type: 'POST',
                    data: { "App_bian": txtbian, "App_KHname": txtKH, "App_xiang": txtqishi, "Fzr": Fzr, "state": 1 },
                    success: function (DAtas) {
                        createRow(DAtas);
                        console.log(DAtas)
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
                function createRow(data) {
                    $('#AppTable tr').remove();
                    $.each(data, function (i, item) {
                        var $tr = $(`<tr>
                                        <td id="CG_ZT">${item.AP_bian}</td>
                                        <td>${item.App_Kehu}</td>
                                        <td>${item.App_qishi}</td>
                                        <td>${item.App_JTime}</td>
                                        <td>${item.APP_name}</td>
                                        <td>${item.App_fzr}</td>
                                        <td><a href ="#" id="CG_CKED" >@Resource.String196</a></td>
                                        <td><a href="#" id="CG_SP">传递至ERP</a></td>
                                    </tr>
                                `);
                        if (item.AP_ren == $("#Login_N").text()) {
                            $('#AppTable').append($tr);
                        }else
                        if ($("#Login_sf").text() == "客户经理" || $("#Login_sf").text() == "销售助理") {
                            $("#AppTable").append($tr);
                        }
                        else if ($("#Login_sf").text() == "销售") {
                            if (item.AP_ren == $("#Login_N").text() || item.App_fzr == $("#Login_N").text()) {
                                $("#AppTable").append($tr);
                            }
                        }
                    })
                }
            }
            $("#findApp").click(function () {
                Application_form_information()
            })
            function FUzher() {
                $.ajax({
                    url: '/Application/Application',
                    type: 'POST',
                    data: { "state": 30 },
                    success: function (path) {
                        if (path == "获取错误") {
                            alert(path)
                        } else {
                            $("#XMfzr option").remove()
                            var $op = $(`<option value=""></optino>`)
                            $("#XMfzr").append($op)
                            $.each(path, function (i, item) {
                                var $op = $(`<option value="${item[0]}">${item[0]}</optino>`)
                                $("#XMfzr").append($op)
                            })
                        }
                    },
                    error: function () {
                        alert("系统错误!");
                    }
                })
            }
            $(function() {
                $(document).on("click", "#CG_CKED", function (e) {
                    $("#Tbodys tr").remove()
                    var HJ_CP_sqd = $(e.target).parent().parent().children().eq(0).text()
                    $("#WT_dh_mb").show()
                    $("#WJ_tjr").text(HJ_CP_sqd)//编码
                    $.ajax({
                        url: '/Application/GetBaoJia',
                        type: 'POST',
                        data: { "state": 1, "bian": HJ_CP_sqd },
                        success: function (path) {
                            $.each(path, function (i, item) {
                                var $op = $(`<tr>
                                                <td>${item.WNm}</td >
                                                <td>${item.SJ_gs}</td>
                                                <td>${item.SJ_Zhua}</td>
                                                <td>${item.SJ_beizhu}</td>
                                                <td style="display: none">${item.SJ_Dizhi}</td>
                                                <td><button id="jisndllp">预览</button></td>
                                            </tr>`)
                                $("#Tbodys").append($op)
                            })
                        },
                        error: function () {
                            alert("系统错误!");
                        }
                    })
                    //window.location.href = "/Technology/SHjixs?App_bian=" + HJ_CP_sqd;
                })
                $(document).on("click", "#CG_SP", function (e) {
                    var HJ_CP_sqd = $(e.target).parent().parent().children().eq(0).text()
                    window.location.href = "/Detailed/BomsView?names=" + HJ_CP_sqd;
                })
                $(document).on("click", "#jisndllp", function () {
                    var bian = $("#WJ_tjr").text()
                    var dizhi = $(this).parent().parent().children().eq(4).text()
                    console.log(bian)
                    window.location.href = "/Admin/Print?Appbian=" + bian + "&path=" + encodeURIComponent(dizhi);
                })
                $(document).on("click", ".quxiao", function () {
                    $("#WT_dh_mb").css({ "display": "none" })
                })
            })
        })
    </script>
}